package com.itheima.pinda.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pinda.DTO.truck.TruckTypeDto;
import com.itheima.pinda.common.utils.PageResponse;
import com.itheima.pinda.common.utils.Result;
import com.itheima.pinda.service.PdTruckTypeService;
import com.itheima.pinda.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@Api(tags = "车辆类型管理")
@RestController
@RequestMapping("base/truckType")
public class PdTruckTypeController {

    @Autowired
    private PdTruckTypeService truckTypeService;

    @ApiOperation(value = "车辆类型新增")
    @PostMapping(value = "/insert")
    public TruckTypeDto truckTypeInsert(TruckTypeDto dto){

        return truckTypeService.truckTypeInsert(dto);
    }

    @ApiOperation(value = "车辆类型修改")
    @PostMapping(value = "/update")
    public TruckTypeDto truckTypeUpdate(TruckTypeDto dto) {

        return truckTypeService.truckTypeInsert(dto);
    }
    @ApiOperation(value = "根据Id查询车辆类型详情")
    @GetMapping(value = "/selectById")
    public TruckTypeDto selectById(@RequestParam("id") String id){

        return truckTypeService.selectById(id);
    }

    @ApiOperation(value = "分页查询车辆类型")
    @PostMapping(value = "/selectByPage")
    public PageResponse selectByPage(@RequestParam("pageNum") Integer pageNum,
                                                   @RequestParam("pageSize") Integer pageSize,
                                                   @RequestParam(value = "name",required = false) String name,
                                                   @RequestParam(value = "allowableLoad",required = false) BigDecimal allowableLoad,
                                                   @RequestParam(value = "allowableVolume",required = false)BigDecimal allowableVolume){

        IPage page = truckTypeService.selectByPage(pageNum, pageSize, name, allowableLoad, allowableVolume);

        return ResultUtils.pageResult(pageNum,pageSize,page);
    }

    @ApiOperation(value = "车辆类型删除")
    @DeleteMapping(value = "/delete")
    public Result truckTypeDelete(@RequestBody List<String> ids){
        truckTypeService.truckTypeDelete(ids);
        return Result.ok("删除成功！");
    }

}
